package com.meixiang.activity.account.manager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.main.MXApplication;
import com.meixiang.util.AbToastUtil;
import com.meixiang.util.DesUtil;
import com.meixiang.view.EnterNewAgainPaymentKeyDialog;
import com.meixiang.view.TitleView;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 修改支付密码   重复输入新密码
 *
 * @author zys
 */
public class EnterNewPasswordAgainActivity extends BaseActivity {

    @Bind(R.id.title)
    TitleView title;
    @Bind(R.id.password)
    EnterNewAgainPaymentKeyDialog password;
    private Activity mActivity;
    private  String ClassStatus;
    String newPwds;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_enter_new_password_again);
        mActivity=EnterNewPasswordAgainActivity.this;
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        title.setTitle(R.string.change_pay_off_password);
        title.setLeftImageButton(R.mipmap.back);
        title.showLeftButton(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ClassStatus=getIntent().getStringExtra("ClassStatus");
    }

    @Override
    protected void initView() {
        if (ClassStatus.equals("3")){
            password.setKeyTitle(R.string.repeatpay_new_password_pay_off);
            password.setInputFinishListener(new EnterNewAgainPaymentKeyDialog.InputFinishListener() {
                @Override
                public void onInputFinish(String pwd) {
                    newPwds= MXApplication.mApp.getSession().get("NewPwd");
                    getVerificationPwd(newPwds,pwd);
                }
            });
            password.juumActivity(PayOffSetNewPasswordActivity.class,ClassStatus);
        }



    }

    @Override
    protected void setData() {
          MXApplication.mApp.AddActivity(mActivity);
    }

    @Override
    public void onClick(View v) {

    }
    private  void getVerificationPwd(String  newPwd,String EnterPwd){
//        newPassword	String	必填			新的支付密码
//        oldPassword
//        if (!newPwd.equals(EnterPwd)){
//            AbToastUtil.showToast(mActivity,"两次输入的密码不一致！");
//        }
        HttpParams  params=new HttpParams();
        params.put("newPassword", DesUtil.md5(newPwd));
        HttpUtils.post(Config.RESETPAYMENTPASSWORD_URL,params, new HttpCallBack(mActivity) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                      if (code.equals("0")){
                          startActivity(new Intent(mActivity,PaymentCodeActivity.class));
                          MXApplication.mApp.RemoveActivity();
                          AbToastUtil.showToast(mActivity,message);
                      }else{
                          AbToastUtil.showToast(mActivity,message);
                      }
            }

            @Override
            public void onError(String code, String message) {
                AbToastUtil.showToast(mActivity,message);
            }
        });


    }



}
